<%-- 
    Document   : times
    Created on : 25/08/2011, 22:50:19
    Author     : Marco Antonio
--%>

<%@page import="controle.ServletGeral"%>
<%@page import="controle.ServletTimes"%>
<%@page import="util.Upload"%>
<%@page import="dao.Dao"%>
<%@page import="entidades.TimeFutebol"%>
<%@page import="entidades.Usuario"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Gerência de Times</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
        <%
            Usuario u = (Usuario) session.getAttribute("logado");
            if (u == null) {
                response.sendRedirect("index.jsp");
            } else if (!u.isAdministrador()) {
                response.sendRedirect("index.jsp");
            }
        %> 
        <div id="pagina">
            <div id="banner"></div>
            <div id="status">
                <p class="esquerda"><a href="admhome.jsp">Administração</a> - Times</p> 
                <p class="direita"><%=u.getUsuario()%>(<a href="ServletGeral">Deslogar</a>)</p>
            </div>
            <div id="menu">
                <ul>
                    <li><a href="perfil.jsp">Perfil</a></li>
                    <li><a href="times.jsp">Times</a></li>
                    <li><a href="campeonatos.jsp">Campeonatos</a></li>
                    <li><a href="rodadas.jsp">Rodadas</a></li>
                    <li><a href="jogos.jsp">Jogos</a></li>
                    <li><a href="resultados.jsp">Resultados</a></li>
                </ul>
            </div>
            <div id="conteudo">
                <h1> Times </h1>
                <form id="FormularioTimes" 
                      name="FormularioTimes" 
                      action="ServletTimes" 
                      method="POST"
                      enctype="multipart/form-data">
                    <!-- Foto (que sera carregada no inputFile) -->
                    <%
                        if (session.getAttribute("time") == null) {

                            // SALVAR

                            out.println("<p>");
                            out.println("<label>Escudo: </label>");
                            out.println("<input type=\"file\" name=\"escudo\" value=\"\" />");
                            out.println("</p>");
                            out.println("<p>");
                            out.println("<label>Nome: </label>");
                            out.println("<input type=\"text\" name=\"nome\" value=\"\" />");
                            out.println("</p>");
                            out.println("<input type=\"submit\" value=\"Salvar\" name=\"op\" />");

                        } else {

                            // EDITAR

                            TimeFutebol t = (TimeFutebol) session.getAttribute("time");
                            out.println("<p>");
                            // Carrega Foto
                            out.println("<img src=\"" + ServletGeral.DIR.substring(1) + t.getEscudo() + "\" "
                                    + "alt=\"" + t.getEscudo() + "\" />");
                            out.println("<label>Escudo: </label>");
                            out.println("<input type=\"file\" name=\"escudo\" value=\"\" />");
                            out.println("</p>");
                            out.println("<p>");
                            out.println("<label>Nome: </label>");
                            out.println("<input type=\"text\" name=\"nome\" value=\"" + t.getNome() + "\" />");
                            out.println("</p>");
                            out.println("<input type=\"submit\" value=\"Editar\" name=\"op\" />");
                        }
                    %>
                </form>
                <hr />
                <%
                    if (!new Dao<TimeFutebol>(TimeFutebol.class).listByNome("").isEmpty()) {
                        out.println("<table border=\"1\">");
                        out.println("<tr>");
                        out.println("<th>Id</th>");
                        out.println("<th>Nome</th>");
                        out.println("</tr>");
                        for (TimeFutebol t : new Dao<TimeFutebol>(TimeFutebol.class).listByNome("")) {
                            out.println("<tr>");
                            out.println("<td>" + t.getId() + "</td>");
                            out.println("<td>" + t.getNome() + "</td>");
                            out.println("<td><a href=\"ServletTimes?id=" + t.getId() + "&op=remover\">Remover</a></td>");
                            out.println("<td><a href=\"ServletTimes?id=" + t.getId() + "&op=editar\">Editar</a></td>");
                            out.println("</tr>");
                        }
                        out.println("</table>");
                    }
                %>
            </div>
        </div>
    </body>
</html>
